#include "main.h"

sbit PWM = P3^2;
int mode0 (void);int mode1 (void);int mode2 (void);
int mode = 0 ,Compare = 0;Count = 0,Speed = 25,jiaodu;
void Timer0Init(void);	

void main()
{
		Timer0Init();
		jiaodu = 90;//直接写角度，没有角度函数
    while(1)
    {   
        switch (mode)
        {
        case 0: break;
        case 1: break;
        case 2: break;
        default:  break;
        }
        
    }
}

int mode0 (void) //工作模式
{
    //work code

    //oled code 
    //显示时间
    //温湿度
    //当前模式
    return 0 ;
}

int mode1 (void)//设置模式
{
    
	return 0;
}

//中断读取按键,控制模式
void readmode () interrupt 0  //按键接INT0
{
     mode++;
     if (mode  >2)
     {
        mode = 0;
     }
     
}

void Timer0Init(void)		//100微秒@11.0592MHz
{
	AUXR &= 0x7F;		//定时器时钟12T模式
	TMOD &= 0xF0;		//设置定时器模式
	TL0 = 0xA4;		//设置定时初值
	TH0 = 0xFF;		//设置定时初值
	TF0 = 0;		//清除TF0标志
	TR0 = 1;		//定时器0开始计时
	EA = 1;
	ET0 = 1;
}

void Timer0_Routine() interrupt 1  //????
{
		TL0 = 0xA4;		//??????
		TH0 = 0xFF;
		Speed = (1/9)*jiaodu+5;
    Compare = 200 - Speed ;
    Count++;
		Count %=200;
    if (Count > Compare)//2500us,?2.5ms
    {
        PWM = 1;
    }
    else
    {
        PWM = 0;
    }

}
